;NSIS Modern User Interface
;Basic Example Script
;Written by Joost Verburg

;--------------------------------
;Include Modern UI

  !include "MUI.nsh"

;--------------------------------
;General

  ;Name and file

Name "Quran Research"
OutFile  "Quran_installer.exe"


;Default installation folder
InstallDir "$PROGRAMFILES\QuranResearch"

;Get installation folder from registry if available
InstallDirRegKey HKCU "Software\QuranResearch" ""
;--------------------------------
;Variables

  Var MUI_TEMP
  Var STARTMENU_FOLDER

;--------------------------------
;Interface Settings

  !define MUI_ABORTWARNING
;Remember the installer language
  !define MUI_LANGDLL_REGISTRY_ROOT "HKCU" 
  !define MUI_LANGDLL_REGISTRY_KEY "Software\QuranResearch" 
  !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"

;--------------------------------
;Pages

  !insertmacro MUI_PAGE_LICENSE "License.txt"
  !insertmacro MUI_PAGE_COMPONENTS
  !insertmacro MUI_PAGE_DIRECTORY

  ;Start Menu Folder Page Configuration
  !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU" 
  !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\QuranResearch" 
  !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
  
  !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER


  !insertmacro MUI_PAGE_INSTFILES
  
  !insertmacro MUI_UNPAGE_CONFIRM
  !insertmacro MUI_UNPAGE_INSTFILES
  
;--------------------------------
;Languages
 
;Languages
  !insertmacro MUI_LANGUAGE "Farsi"
#  !insertmacro MUI_LANGUAGE "English" # first language is the default language
 # !insertmacro MUI_LANGUAGE "Arabic"
  #!insertmacro MUI_LANGUAGE "Indonesian"

;--------------------------------
;License Language String

#  LicenseLangString MUILicense ${LANG_ENGLISH} "${NSISDIR}\Docs\Modern UI\License.txt"
#  LicenseLangString MUILicense ${LANG_ARABIC} "${NSISDIR}\Docs\Modern UI\License.txt"
  LicenseLangString MUILicense ${LANG_FARSI} "${NSISDIR}\Docs\Modern UI\License.txt"
#  LicenseLangString MUILicense ${LANG_INDONESIAN} "${NSISDIR}\Docs\Modern UI\License.txt"


;--------------------------------
;Installer Sections

Function .onInit
	!insertmacro MUI_LANGDLL_DISPLAY
        # the plugins dir is automatically deleted when the installer exits
        InitPluginsDir
        File /oname=$PLUGINSDIR\splash.bmp ".\images\splash.bmp"
        #optional
        #File /oname=$PLUGINSDIR\splash.wav "C:\myprog\sound.wav"

        advsplash::show 1000 600 400 -1 $PLUGINSDIR\splash

        Pop $0          ; $0 has '1' if the user closed the splash screen early,
                        ; '0' if everything closed normally, and '-1' if some error occurred.

        Delete $PLUGINSDIR\splash.bmp
FunctionEnd


Section "!Core" SecDummy

  SetOutPath "$INSTDIR"
  
  
  File /r dist\*.*

  SetOutPath "c:\qresmysql"

  File /r MySQL\*.*
  File /r sql\*.*

  ReadEnvStr $0 WINDIR
  SetOutPath "$0\fonts"
  File /r BFonts\*.TTF

  ;Store installation folder
  WriteRegStr HKCU "Software\QuranResearch" "" $INSTDIR


  
  ;Create uninstaller
  WriteUninstaller "$INSTDIR\Uninstall.exe"


  !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
    
    ;Create shortcuts
    CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
    CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\QuranResearch.lnk" "$INSTDIR\main.exe"
    CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
  
  !insertmacro MUI_STARTMENU_WRITE_END

  Exec '"$INSTDIR\start_mysql_server.bat"'

SectionEnd

;--------------------------------
;Descriptions

  ;Language strings
  LangString DESC_SecDummy ${LANG_ENGLISH} "A test section."

  ;Assign language strings to sections
  !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
    !insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
  !insertmacro MUI_FUNCTION_DESCRIPTION_END

;--------------------------------
;Uninstaller Section

Section "Uninstall"

  ;ADD YOUR OWN FILES HERE...

  Delete "$INSTDIR\Uninstall.exe"

  RMDir /r "$INSTDIR"


  !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
    
  Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
  
  ;Delete empty start menu parent diretories
  StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
 
  startMenuDeleteLoop:
	ClearErrors
    RMDir $MUI_TEMP
    GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
    
    IfErrors startMenuDeleteLoopDone
  
    StrCmp $MUI_TEMP $SMPROGRAMS startMenuDeleteLoopDone startMenuDeleteLoop
  startMenuDeleteLoopDone:


  DeleteRegKey /ifempty HKCU "Software\QuranResearch"
SectionEnd

